package cn.ecut.request;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;


public class FileUploadServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        throw new RuntimeException("不支持Get方式上传文件") ;
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Part source = request.getPart("source");
        System.out.println( source );
        System.out.println( source.getName() );
        System.out.println( source.getSize() );
        System.out.println( source.getSubmittedFileName() );
        System.out.println( source.getContentType() );
        /**
         * Part{n=source,fn=test.jpg,ct=image/jpeg,s=258957,t=true,f=null}
         * source
         * 258957
         * test.jpg
         * image/jpeg
         */
        source.write( source.getSubmittedFileName() );
    }
}
